//
//  Data.m
//  dingding
//
//  Created by dingding on 15/12/2.
//  Copyright © 2015年 dingding. All rights reserved.
//

#import "SaveHelper.h"
#import "NSMutableDictionary+AllType.h"

@implementation SaveHelper

+(void)saveStr:(NSString*)key vlu:(NSString*)value
{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    [defaults setObject: value forKey:key];
    [defaults synchronize];
}

+(NSString*)getSaveStr:(NSString*)key
{
    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:key];//根据键值取出
}

+(void)saveInt:(NSString*)key vlu:(int)value
{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    [defaults setObject:[NSString stringWithFormat:@"%d",value] forKey:key];
    [defaults synchronize];
}

+(int)getSaveInt:(NSString*)key
{
    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults]; 
    NSString* str=[defaults objectForKey:key];
    if(!str)return 0;
    return [str intValue];
}

+(void)saveBool:(NSString*)key vlu:(bool)value
{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    [defaults setObject:[NSString stringWithFormat:@"%d",value?1:0] forKey:key];
    [defaults synchronize];
}

+(bool)getSaveBool:(NSString*)key
{
    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
    NSString* str=[defaults objectForKey:key];
    if(!str)return NO;
    return [str intValue]==1;
}

+(BOOL)getSaveBoolDefalutYES:(NSString*)key
{
    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
    NSString* str=[defaults objectForKey:key];
    if(!str)return YES;
    return [str intValue]==1;
}

+(void)saveDict:(NSString*)key dict:(NSDictionary*)dict
{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    [defaults setObject:dict forKey:key];
    [defaults synchronize];
}

+(NSDictionary*)getSaveDict:(NSString*)key
{
    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
    NSDictionary* dict=[defaults objectForKey:key];
    return dict;
}
@end
